package com.hb.trans.mvp.model

import android.location.Location
import com.basiclib.base.BaseModel
import com.hb.trans.api.EndPoints
import com.hb.trans.api.TRANS_SERVER_PATH
import com.hb.trans.bean.Base
import com.hb.trans.bean.City
import com.hb.trans.bean.Geocoder
import com.hb.trans.bean.School
import com.hb.trans.mvp.contract.SchoolsContract
import io.reactivex.Observable
import javax.inject.Inject

class SchoolsModel @Inject constructor(var api: EndPoints) : BaseModel(), SchoolsContract.Model {
    override fun findSchools(name: String): Observable<Base<MutableList<School>>> {
        return api.findSchools("${TRANS_SERVER_PATH}schInfo/queryByName", name)
    }

    override fun getCounties(): Observable<Base<MutableMap<String, MutableList<City>>>> {
        return api.getCounties("${TRANS_SERVER_PATH}schInfo/getCode")
    }

    override fun getLocationInfo(location: Location): Observable<Geocoder> {
        val params = mutableMapOf(
//            "callback" to "renderReverse",
            "location" to "${location.latitude},${location.longitude}",
            "coordtype" to "wgs84ll",
            "output" to "json",
            "ak" to "134db1b9cf1f1f2b4427210932b34dcb"
        )
        return api.geocoder("http://api.map.baidu.com/geocoder/v2/", params)
    }

    override fun getSchools(district: String): Observable<Base<MutableList<School>>> {

        return api.getSchools("${TRANS_SERVER_PATH}schInfo/getByDistrict", district)
    }

}
